package com.yanqu.road.server.cross3server.cmd.xrank;

import com.yanqu.road.entity.rank.xrank.XChannelRankPart;
import com.yanqu.road.logic.pb.XRankPb;
import com.yanqu.road.logic.xlogic.rank.channel.XChannelRankListModel;
import com.yanqu.road.logic.xlogic.rank.channel.XChannelRankMap;
import com.yanqu.road.pb.cross3.activity.XRankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.cross3server.manager.Cross3XRankMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Cross3Protocol;

import java.util.List;

@Cmd(code = Cross3Protocol.C3_XRANK_GET_CHANNEL_RANK_PART_LIST, desc = "区域榜单 个人贡献")
public class XRankGetChannelRankPartListFromGameCmd extends CrossCommand {

    private int activityId;
    private int conditionType;

    private int channelId;

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        XRankProto.GetXChannelRankPartListReqMsg reqMsg = XRankProto.GetXChannelRankPartListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        conditionType = reqMsg.getConditionType();
        channelId = reqMsg.getChannelId();

        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        XChannelRankMap channelRankMap = Cross3XRankMgr.getChannelRankMap();
        XChannelRankListModel model = channelRankMap.getChannelRankListModel(activityId, conditionType);
        List<XChannelRankPart> rankList = model.getPartValueRankList(channelId);
        XRankProto.XChannelRankPartListMsg.Builder rankBuilder = XRankPb.parseXChannelRankPartListMsg(activityId, conditionType, rankList);

        XRankProto.GetXChannelRankPartListRespMsg.Builder builder = XRankProto.GetXChannelRankPartListRespMsg.newBuilder();
        builder.setRet(0);
        builder.setPartList(rankBuilder);
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_XRANK_GET_CHANNEL_RANK_PART_LIST, builder);
        MessageHelper.sendPacket(serverId, userId, message);
    }

    @Override
    public void sendData() {

    }
}
